/**
 * 
 */
package vue.globalBar;

import java.awt.event.MouseEvent;

import model.session.SolverExecutionBlock;
import vue.popup.JPopupSolver;
import vue.session.IGSolverBlock;
import controller.ISessionManager;

/**
 * A representation of a solver for the GlobalBar. It is somehow associate to
 * {@link SolverExecutionBlock}.
 * 
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class IGBarSolver extends IGBarExecution {


	private static final long	serialVersionUID	= 1L;

	private IGSolverBlock		solver;

	/**
	 * Create an {@link IGBarSolver}.
	 * 
	 * @param exec
	 *            the {@link IGSolverBlock} associate
	 * @param manager
	 *            the session manager
	 */
	public IGBarSolver(IGSolverBlock exec, ISessionManager manager) {
		super(null, manager);

		this.solver = exec;

		rightMenu = new JPopupSolver(exec, manager);

		refresh();
	}

	@Override
	public void refresh() {
		description.setText(solver.getSolver().getSolver().getType().getDescription());
		state.setText(solver.getSolver().getRes().getStatus().name());

		if (solver.getSolver().getRes() == null)
		{// pas de res
			time.setText(TIME_PREFIX + UNKNOW);
			memory.setText(MEMORY_PREFIX + UNKNOW);
		}
		else
		{// result dispo
			time.setText(TIME_PREFIX + solver.getSolver().getRes().getPreprocTime());
			memory.setText(MEMORY_PREFIX + solver.getSolver().getRes().getMemoryUsed());
		}

		rightMenu.refresh();
	}

	/**
	 * Return the {@link IGSolverBlock} associate.
	 * 
	 * @return the {@link IGSolverBlock} associate.
	 */
	public IGSolverBlock getSolver() {
		return solver;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		solver.notifySelected();
	}


}
